package kg.aibek.projecteuler.p10;

import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Problem22 {
	public void solve() throws FileNotFoundException {
		String str;

		Scanner scan = new Scanner(new File(
				"C://Users/aosmonov/Desktop/names.txt"));

		str = scan.nextLine();

		String[] ss = str.split(",");

		Arrays.sort(ss);

		BigInteger bi = BigInteger.ZERO;
		for (int i = 0; i < ss.length; i++) {
			int a = i + 1;
			bi = bi.add(new BigInteger(a * getWordScore(ss[i]) + ""));
		}

		System.out.println(bi);
	}

	private int getWordScore(String word) {
		int count = 0;
		for (char ch : word.toCharArray()) {
			if (ch != '"') {
				count += (ch - 64);
			}
		}
		return count;
	}

	public static void main(String[] args) {
		Problem22 p = new Problem22();
		try {
			p.solve();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
